/* Copyright Statement:
 *
 * This software/firmware and related documentation ("MediaTek Software") are
 * protected under relevant copyright laws. The information contained herein
 * is confidential and proprietary to MediaTek Inc. and/or its licensors.
 * Without the prior written permission of MediaTek inc. and/or its licensors,
 * any reproduction, modification, use or disclosure of MediaTek Software,
 * and information contained herein, in whole or in part, shall be strictly prohibited.
 */
/* MediaTek Inc. (C) 2010. All rights reserved.
 *
 * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
 * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
 * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
 * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
 * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
 * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
 * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
 * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
 * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
 * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
 * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
 * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
 * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
 * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
 * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
 * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
 *
 * The following software/firmware and/or related documentation ("MediaTek Software")
 * have been modified by MediaTek Inc. All revisions are subject to any receiver's
 * applicable license agreements with MediaTek Inc.
 */

/*
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */
/*
 * Definitions for stk3a5x als/ps sensor chip.
 */
#ifndef __STK3A5X_H__
#define __STK3A5X_H__

#include <linux/ioctl.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/of_irq.h>
#include <linux/gpio.h>
#include <linux/of_gpio.h>
#include <linux/regulator/consumer.h>
#include "cust_alsps.h"
#include "alsps.h"

#define DRIVER_VERSION           "1.0.0"
#define STK3A5X_DEV_NAME		 "stk3a5x"
#define APS_TAG                  "[ALS/PS] "

#define APS_DBG_FEATURE
#ifdef APS_DBG_FEATURE 
#define APS_FUN(f)               printk(KERN_INFO APS_TAG" %s\n", __FUNCTION__)
#define APS_ERR(fmt, args...)    printk(KERN_ERR APS_TAG" %s %d: "fmt"\n", __FUNCTION__, __LINE__, ##args)
#define APS_LOG(fmt, args...)    printk(KERN_INFO APS_TAG" %s %d: "fmt"\n", __FUNCTION__, __LINE__, ##args)
#define APS_DBG(fmt, args...)    printk(KERN_INFO APS_TAG" %s %d: "fmt"\n", __FUNCTION__, __LINE__, ##args)

#else
#define APS_FUN(fmt, args...)                                                  \
        do {                                                                   \
        } while (0)

#define APS_ERR(fmt, args...)                                                  \
        do {                                                                   \
        } while (0)

#define APS_LOG(fmt, args...)                                                  \
        do {                                                                   \
        } while (0)

#define APS_DBG(fmt, args...)                                                  \
        do {                                                                   \
        } while (0)

#endif


//#define misc_dev
#define factory_dev
#define STK_TUNE0
#define STK_PS_CALI
#define STK_ALS_CALI
//#define STK_ALS_MID_FIR
//#define STK_PS_MULTI_PERSIST
//#define STK_PERIOD_REFRESH
#define STK_ALS_SKIP

/* Define Register Map */
#define STK3A5X_STATE_REG                   0x00
#define STK3A5X_PSCTRL_REG                  0x01
#define STK3A5X_ALSCTRL1_REG                0x02
#define STK3A5X_LEDCTRL_REG                 0x03
#define STK3A5X_INTCTRL1_REG                0x04
#define STK3A5X_WAIT_REG                    0x05
#define STK3A5X_THDH1_PS_REG                0x06
#define STK3A5X_THDH2_PS_REG                0x07
#define STK3A5X_THDL1_PS_REG                0x08
#define STK3A5X_THDL2_PS_REG                0x09
#define STK3A5X_THDH1_ALS_REG               0x0A
#define STK3A5X_THDH2_ALS_REG               0x0B
#define STK3A5X_THDL1_ALS_REG               0x0C
#define STK3A5X_THDL2_ALS_REG               0x0D
#define STK3A5X_FLAG_REG                    0x10
#define STK3A5X_DATA1_PS_REG                0x11
#define STK3A5X_DATA2_PS_REG                0x12
#define STK3A5X_DATA1_ALS_REG               0x13
#define STK3A5X_DATA2_ALS_REG               0x14
#define STK3A5X_DATA1_ALS1_REG              0x17
#define STK3A5X_DATA2_ALS1_REG              0x18
#define STK3A5X_DATA1_C_REG                 0x1B
#define STK3A5X_DATA2_C_REG                 0x1C
#define STK3A5X_DATA1_PS_OFFSET_REG         0x1D
#define STK3A5X_DATA2_PS_OFFSET_REG         0x1E
#define STK3A5X_PDT_ID_REG                  0x3E
#define STK3A5X_RSRVD_REG                   0x3F
#define STK3A5X_GAINCTRL_REG                0x4E
#define STK3A5X_SW_RESET_REG                0x80
#define STK3A5X_SW_PDCTRL_REG               0xA1
#define STK3A5X_SW_INTCTRL2_REG             0xA5

/* Define state reg */

#define STK3A5X_STATE_EN_CT_AUTOK_SHIFT        4
#define STK3A5X_STATE_EN_INTELL_PRST_SHIFT     3
#define STK3A5X_STATE_EN_WAIT_SHIFT            2
#define STK3A5X_STATE_EN_ALS_SHIFT             1
#define STK3A5X_STATE_EN_PS_SHIFT              0

#define STK3A5X_STATE_EN_CT_AUTOK_MASK         0x10
#define STK3A5X_STATE_EN_INTELL_PRST_MASK      0x08
#define STK3A5X_STATE_EN_IRO_MASK              0x10
#define STK3A5X_STATE_EN_WAIT_MASK             0x04
#define STK3A5X_STATE_EN_ALS_MASK              0x02
#define STK3A5X_STATE_EN_PS_MASK               0x01

/* Define PS ctrl reg */
#define STK3A5X_PS_PRS_SHIFT            6
#define STK3A5X_PS_GAIN_SHIFT           4
#define STK3A5X_PS_IT_SHIFT             0

#define STK3A5X_PS_PRS_MASK             0xC0
#define STK3A5X_PS_GAIN_MASK            0x30
#define STK3A5X_PS_IT_MASK              0x0F

/* Define ALS ctrl reg */
#define STK3A5X_ALS_PRS_SHIFT           6
#define STK3A5X_ALS_GAIN_SHIFT          4
#define STK3A5X_ALS_IT_SHIFT            0

#define STK3A5X_ALS_PRS_MASK            0xC0
#define STK3A5X_ALS_GAIN_MASK           0x30
#define STK3A5X_ALS_IT_MASK             0x0F

/* Define LED ctrl reg */
#define STK3A5X_EN_CTIR_SHIFT           0
#define STK3A5X_EN_CTIRFC_SHIFT         1
#define STK3A5X_LED_IRDR_SHIFT          6
#define STK3A5X_EN_CTIR_MASK            0x01
#define STK3A5X_EN_CTIRFC_MASK          0x02
#define STK3A5X_LED_IRDR_MASK           0xC0

/* Define interrupt reg */
#define STK3A5X_INT_CTRL_SHIFT          7
#define STK3A5X_INT_INVALID_PS_SHIFT    5
#define STK3A5X_INT_ALS_SHIFT           3
#define STK3A5X_INT_PS_SHIFT            0
#define STK3A5X_INT_CTRL_MASK           0x80
#define STK3A5X_INT_INVALID_PS_MASK     0x20
#define STK3A5X_INT_ALS_MASK            0x08
#define STK3A5X_INT_PS_MASK             0x07
#define STK3A5X_INT_ALS                 0x08

/* Define flag reg */
#define STK3A5X_FLG_ALSDR_SHIFT         7
#define STK3A5X_FLG_PSDR_SHIFT          6
#define STK3A5X_FLG_ALSINT_SHIFT        5
#define STK3A5X_FLG_PSINT_SHIFT         4
#define STK3A5X_FLG_OUI_SHIFT           2
#define STK3A5X_FLG_IR_RDY_SHIFT        1
#define STK3A5X_FLG_NF_SHIFT            0

#define STK3A5X_FLG_ALSDR_MASK          0x80
#define STK3A5X_FLG_PSDR_MASK           0x40
#define STK3A5X_FLG_ALSINT_MASK         0x20
#define STK3A5X_FLG_PSINT_MASK          0x10
#define STK3A5X_FLG_OUI_MASK            0x04
#define STK3A5X_FLG_IR_RDY_MASK         0x02
#define STK3A5X_FLG_NF_MASK             0x01

/* Define ALS CTRL-2 reg */
#define STK3A5X_ALSC_GAIN_SHIFT         0x04
#define STK3A5X_ALSC_GAIN_MASK          0x30

/* Define INT-2 reg */
#define STK3A5X_INT_ALS_DR_SHIFT        0x01
#define STK3A5X_INT_PS_DR_SHIFT         0x00
#define STK3A5X_INT_ALS_DR_MASK         0x02
#define STK3A5X_INT_PS_DR_MASK          0x01

/* Define ALS/PS parameters */
#define STK3A5X_PS_PRS1                0x00
#define STK3A5X_PS_PRS2                0x40
#define STK3A5X_PS_PRS4                0x80
#define STK3A5X_PS_PRS16               0xC0

#define STK3A5X_PS_GAIN1               0x00
#define STK3A5X_PS_GAIN2               0x10
#define STK3A5X_PS_GAIN4               0x20
#define STK3A5X_PS_GAIN8               0x30

#define STK3A5X_PS_IT100               0x00
#define STK3A5X_PS_IT200               0x01
#define STK3A5X_PS_IT400               0x02
#define STK3A5X_PS_IT800               0x03

#define STK3A5X_ALS_PRS1               0x00
#define STK3A5X_ALS_PRS2               0x40
#define STK3A5X_ALS_PRS4               0x80
#define STK3A5X_ALS_PRS8               0xC0

#define STK3A5X_ALS_GAIN1              0x00
#define STK3A5X_ALS_GAIN4              0x10
#define STK3A5X_ALS_GAIN16             0x20
#define STK3A5X_ALS_GAIN64             0x30

#define STK3A5X_ALS_IT25               0x00
#define STK3A5X_ALS_IT50               0x01
#define STK3A5X_ALS_IT100              0x02
#define STK3A5X_ALS_IT200              0x03

#define STK3A5X_ALSC_GAIN1             0x00
#define STK3A5X_ALSC_GAIN4             0x10
#define STK3A5X_ALSC_GAIN16            0x20
#define STK3A5X_ALSC_GAIN64            0x30

#define STK3A5X_LED_3_125mA            0x00
#define STK3A5X_LED_6_25mA             0x20
#define STK3A5X_LED_12_5mA             0x40
#define STK3A5X_LED_25mA               0x60
#define STK3A5X_LED_50mA               0x80
#define STK3A5X_LED_100mA              0xA0
#define STK3A5X_LED_150mA              0xC0

#define STK3A5X_WAIT20                 0x0C
#define STK3A5X_WAIT50                 0x20
#define STK3A5X_WAIT100                0x40

#define STK3A5X_INTELL_20              0x32
#define STK3A5X_BGIR_PS_INVALID        0x28
#define STK_PS_CALI_DATA_NUM           3
#define STK3A5X_PS_BGIR_THRESHOLD      0x64
#define STK3A5X_PID_LIST_NUM           5

#define STK3A5X_MAX_MIN_DIFF           200
#define STK3A5X_LT_N_CT                170
#define STK3A5X_HT_N_CT                220

#ifdef STK_TUNE0
    #define STK3A5X_SMUDGE_DIFF         300
    #define STK3A5X_SMUDGE_NT           300
    #define STK3A5X_SMUDGE_FT           250
    #define STK3A5X_TRACKING_QUANTI     4
    #define STK3A5X_QUANTI_RANGE        10
#endif  /* #ifdef STK_TUNE0 */

#define STK3A5X_ALS_THRESHOLD           10
#define STK3A5X_PS_BGIR_INVALID         0x7FFF0001
#define STK3A5X_PS_DATA_UNAVAILABLE     0x7FFF0002
#define STK3A5X_CALI_FILE               "/data/misc/sensor/stkalpscali.conf"
#define STK3A5X_ALS_CALI_TARGET_LUX     500
#define STK3A5X_PS_CALI_TIMES           5
#define STK3A5X_PS_CALI_MAX_CROSSTALK   3000
#define STK3A5X_PS_CALI_DIFF            40
#define STK_CHANNEL_NUMBER              3
#define STK_CHANNEL_OFFSET              3
#define STK_CHANNEL_GOLDEN              10

typedef enum
{
    STK3A5X_NONE        = 0x0,
    STK3A5X_ALS         = 0x1,
    STK3A5X_PS          = 0x2,
    STK3A5X_ALL         = 0x4,
} stk3a5x_sensor_type;

typedef enum
{
#ifdef STK_TUNE0
    STK3A5X_TUNE0_TIMER,
#endif
    STK3A5X_DATA_TIMER_ALPS,
    STK3A5X_BOOT_REPORT_TIMER_PS,
#ifdef STK_ALS_SKIP
    STK3A5X_SKIP_TIMER_ALS,
#endif
} stk3a5x_timer_type;

typedef enum
{
    STK3A5X_CALI_TIMER_ALS,
    STK3A5X_CALI_TIMER_PS,
} stk3a5x_cali_timer_type;

typedef struct stk3a5x_register_table
{
    uint8_t address;
    uint8_t value;
    uint8_t mask_bit;
} stk3a5x_register_table;

typedef enum
{
    STK3A5X_PRX_FAR_AWAY,
    STK3A5X_PRX_NEAR_BY,
    STK3A5X_PRX_NEAR_BY_UNKNOWN
} stk3a5x_prx_nearby_type;

typedef struct stk3a5x_timer_info
{
    bool                        timer_is_active;
    bool                        timer_is_exist;
} stk3a5x_timer_info;

typedef struct stk3a5x_irq_info
{
    bool                        irq_is_active;
    bool                        irq_is_exist;
} stk3a5x_irq_info;

#if (defined(STK_ALS_CALI) | defined(STK_PS_CALI))
typedef enum
{
    STK3A5X_CALI_IDLE,
    STK3A5X_CALI_RUNNING,
    STK3A5X_CALI_FAILED,
    STK3A5X_CALI_DONE
} stk3a5x_calibration_status;
#endif

typedef struct stk3a5x_cali_table
{
    uint32_t als_version;
    uint32_t ps_version;
    uint32_t als_scale;
    uint32_t als_bias;
    uint32_t ps_near_thd;
    uint32_t ps_far_thd;
    uint32_t ps_ctir;
} stk3a5x_cali_table;

typedef struct stk3a5x_cali_info
{
#if (defined(STK_ALS_CALI) | defined(STK_PS_CALI))
    stk3a5x_timer_info          timer_status;
    stk3a5x_cali_timer_type     cali_sensor;
    stk3a5x_calibration_status  cali_status;
#endif
    stk3a5x_cali_table          cali_para;
} stk3a5x_cali_info;


typedef struct stk3a5x_ps_info
{
    bool                        first_init;
    bool                        cali_enable;
    float                       sampling_rate_hz;
    uint64_t                    sampling_intvl;
    bool                        enable;
    bool                        sr_enable;
    bool                        boot_enable;
    uint16_t                    thd_near;
    uint16_t                    thd_far;
    uint16_t                    ht_n_ct;
    uint16_t                    lt_n_ct;
    uint16_t                    max_min_diff;
    stk3a5x_prx_nearby_type     last_nearby;
    uint16_t                    last_raw_data;
    uint8_t                     ps_ctrl_reg;
    bool                        is_dri;
#ifdef STK_TUNE0
    uint16_t                    psa;
    uint16_t                    psi;
    uint16_t                    psi_set;
    bool                        tune_zero_init_proc;
    uint32_t                    ps_stat_data[STK_PS_CALI_DATA_NUM];
    int16_t                     data_count;
    int16_t                     smudge_count;
    bool                        tune0_done;
    bool                        smudge_update;
#endif
    bool                        ps_report;
    bool                        bgir_update;
    uint8_t                     cali_failed_count;
    uint16_t                    ps_cali_data[STK_PS_CALI_DATA_NUM];
    uint32_t                    ps_cali_data_avg;
    uint8_t                     ps_cali_loop;
    int 						fac_cali;
} stk3a5x_ps_info;

typedef struct stk3a5x_als_info
{
    bool                        first_init;
    bool                        cali_enable;
    float                       sampling_rate_hz;
    uint64_t                    sampling_intvl;
    bool                        enable;
    bool                        sr_enable;
    uint8_t                     als_ctrl_reg;
    uint32_t                    scale;
    bool                        is_dri;
#ifdef STK_ALS_MID_FIR
    stk3a5x_data_filter         als_data_filter;
#endif
    uint8_t                     cali_failed_count;
    uint16_t                    last_raw_data[5];
    uint16_t                    als_cali_data;
    uint16_t                    last_lux;
    bool                        als_skip;
} stk3a5x_als_info;

struct stk3a5x_data
{
    struct alsps_hw  hw;
    struct i2c_client *client;
    struct device *dev;
    struct delayed_work  eint_work;
    const struct stk3a5x_bus_ops *bops;
    /*misc*/
    struct device_node *irq_node;
    int    stk_irq;
    struct mutex  io_lock;
    /*data*/
    atomic_t i2c_retry;
    atomic_t als_suspend;
    atomic_t als_debounce;	/*debounce time after enabling als */
    atomic_t als_deb_on;	/*indicates if the debounce is on */
    atomic_t als_deb_end;	/*the jiffies representing the end of debounce */
    atomic_t ps_mask;	/*mask ps: always return far away */
    atomic_t ps_debounce;	/*debounce time after enabling ps */
    atomic_t ps_deb_on;	/*indicates if the debounce is on */
    atomic_t ps_deb_end;	/*the jiffies representing the end of debounce */
    atomic_t ps_suspend;
    atomic_t trace;
    atomic_t init_done;
    /*early suspend*/
#if defined(CONFIG_HAS_EARLYSUSPEND)
    struct early_suspend    early_drv;
#endif
    uint8_t pid;
    ktime_t                 alps_poll_delay;
    struct work_struct      stk_alps_work;
    struct hrtimer          alps_timer;
    struct workqueue_struct *stk_alps_wq;
    int                     int_pin;
    int32_t                 irq;
    struct work_struct      stk_irq_work;
    struct workqueue_struct *stk_irq_wq;
    stk3a5x_irq_info        irq_status;
#ifdef STK_TUNE0
    struct hrtimer          ps_tune0_timer;
    struct workqueue_struct *stk_ps_tune0_wq;
    struct work_struct      stk_ps_tune0_work;
    ktime_t                 ps_tune0_delay;
    stk3a5x_timer_info      tune0_timer_info;
#endif
#ifdef STK_ALS_SKIP
    struct hrtimer          als_skip_timer;
    struct workqueue_struct *stk_als_skip_wq;
    struct work_struct      stk_als_skip_work;
    ktime_t                 als_skip_delay;
    stk3a5x_timer_info      als_skip_timer_info;
#endif
#if (defined(STK_ALS_CALI) || defined(STK_PS_CALI))
    struct hrtimer          cali_timer;
    struct workqueue_struct *stk_cali_wq;
    struct work_struct      stk_cali_work;
    ktime_t                 cali_poll_delay;
#endif
    stk3a5x_cali_info       cali_info;
    atomic_t                recv_reg;
    stk3a5x_ps_info         ps_info;
    stk3a5x_als_info        als_info;
    stk3a5x_timer_info      alps_timer_info;
    bool                    first_init;
};

struct stk3a5x_bus_ops
{
    u16 bustype;
    int (*read)(struct stk3a5x_data *, unsigned char);
    int (*read_block)(struct stk3a5x_data *, unsigned char, int, void *);
    int (*write)(struct stk3a5x_data *, unsigned char, unsigned char);
    int (*write_block)(struct stk3a5x_data *, unsigned char, unsigned char *, unsigned char);
    int (*read_modify_write)(struct stk3a5x_data *, unsigned char, unsigned char, unsigned char);
};

int stk3a5x_probe(struct i2c_client *client,
                  const struct stk3a5x_bus_ops *bops);
int stk3a5x_remove(struct i2c_client *client);
int stk3a5x_suspend(struct device *dev);
int stk3a5x_resume(struct device *dev);
int stk3a5x_create_attr(void);
int stk3a5x_delete_attr(void);
extern int stk3a5x_init_flag;

ssize_t config_show(struct device_driver *ddri, char *buf);
ssize_t config_store(struct device_driver *ddri, const char *buf, size_t count);
ssize_t trace_show(struct device_driver *ddri, char *buf);
ssize_t trace_store(struct device_driver *ddri, const char *buf, size_t count);
ssize_t als_show(struct device_driver *ddri, char *buf);
ssize_t lux_show(struct device_driver *ddri, char *buf);
ssize_t lux_store(struct device_driver *ddri, const char *buf, size_t count);
ssize_t ps_show(struct device_driver *ddri, char *buf);
ssize_t send_show(struct device_driver *ddri, char *buf);
ssize_t send_store(struct device_driver *ddri, const char *buf, size_t count);
ssize_t recv_show(struct device_driver *ddri, char *buf);
ssize_t recv_store(struct device_driver *ddri, const char *buf, size_t count);
ssize_t allreg_show(struct device_driver *ddri, char *buf);
ssize_t status_show(struct device_driver *ddri, char *buf);
ssize_t distance_show(struct device_driver *ddri, char *buf);

int32_t stk3a5x_ps_get_data_without_notify(struct stk3a5x_data *alps_data, uint16_t *raw_data);
void stk3a5x_get_reg_default_setting(uint8_t reg, uint16_t* value);
#if (defined(STK_ALS_CALI)|| defined(STK_PS_CALI))
    ssize_t cali_show(struct device_driver *ddri, char *buf);
    ssize_t cali_store(struct device_driver *ddri, const char *buf, size_t count);
    int32_t stk3a5x_cali_als(struct stk3a5x_data *alps_data);
    int32_t stk3a5x_cali_ps(struct stk3a5x_data *alps_data);
#endif
#ifdef STK_TUNE0
    ssize_t psmaxdiff_store(struct device_driver *ddri, const char *buf, size_t count);
    ssize_t psmaxdiff_show(struct device_driver *ddri, char *buf);
    ssize_t psltnct_store(struct device_driver *ddri, const char *buf, size_t count);
    ssize_t psltnct_show(struct device_driver *ddri, char *buf);
    ssize_t pshtnct_store(struct device_driver *ddri, const char *buf, size_t count);
    ssize_t pshtnct_show(struct device_driver *ddri, char *buf);
    int32_t stk3a5x_set_ps_thd(struct stk3a5x_data *alps_data, uint16_t thd_h, uint16_t thd_l);
    int stk3a5x_ps_val(struct stk3a5x_data *alps_data);
    void stk3a5x_ps_smudge_judgement(struct stk3a5x_data *alps_data, uint16_t ps_raw_data);
    void stk3a5x_ps_tune0_timer_thread(struct work_struct *work);
#endif
#ifdef STK_ALS_SKIP
void stk3a5x_als_skip_task(struct work_struct *work);
#endif

typedef enum
{
    STK_TRC_ALS_DATA = 0x0001,
    STK_TRC_PS_DATA = 0x0002,
    STK_TRC_EINT = 0x0004,
    STK_TRC_IOCTL = 0x0008,
    STK_TRC_I2C = 0x0010,
    STK_TRC_CVT_ALS = 0x0020,
    STK_TRC_CVT_PS = 0x0040,
    STK_TRC_DEBUG = 0x8000,
} STK_TRC;

#define STK3A5X_REG_READ(stk, reg)  						((stk)->bops->read((stk), reg))
#define STK3A5X_REG_WRITE(stk, reg, val)    				((stk)->bops->write((stk), reg, val))
#define STK3A5X_REG_WRITE_BLOCK(stk, reg, val, len)    		((stk)->bops->write_block((stk), reg, val, len))
#define STK3A5X_REG_READ_MODIFY_WRITE(stk, reg, val, mask)  ((stk)->bops->read_modify_write((stk), reg, val, mask))
#define STK3A5X_REG_BLOCK_READ(stk, reg, count, buf)    	((stk)->bops->read_block((stk), reg, count, buf))
#define STK_ABS(x)              ((x < 0)? (-x):(x))

#endif
